/**
 * Copyright(C) 2008 Matthias Braunhofer
 * All rights reserved
 *
 * Created on: 28.07.2008
*/

package it.cums.ui.wizards;

import it.cums.ui.localization.Messages;

import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

public class CustomerBasicWizardPage extends WizardPage implements IWizardPage {
	private Text nameText;
	private Text referencePersonText;
	private Text taxNumberText;
	private Composite container;
	
	public CustomerBasicWizardPage() {
		super(Messages.CustomerBasicWizardPage_0);
		setTitle(Messages.CustomerBasicWizardPage_1);
		setDescription(Messages.CustomerBasicWizardPage_2);
	}

	
	public void createControl(Composite parent) {
		container = new Composite(parent, SWT.NULL);
		GridLayout layout = new GridLayout();
		container.setLayout(layout);
		layout.numColumns = 2;
		Label label1 = new Label(container, SWT.NULL);
		label1.setText(Messages.CustomerBasicWizardPage_3);
		
		nameText = new Text(container, SWT.BORDER | SWT.SINGLE);
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
		nameText.setLayoutData(gd);
		nameText.addModifyListener(new ModifyListener() {
			
			public void modifyText(ModifyEvent arg0) {
				dialogChanged();
			}
        });
		
		Label label3 = new Label(container, SWT.NULL);
		label3.setText(Messages.CustomerBasicWizardPage_4);
		
		taxNumberText = new Text(container, SWT.BORDER | SWT.SINGLE);
		taxNumberText.setLayoutData(gd);
		taxNumberText.addModifyListener(new ModifyListener() {
			
			public void modifyText(ModifyEvent arg0) {
				dialogChanged();
			}
        });
		
		Label label2 = new Label(container, SWT.NULL);
		label2.setText(Messages.CustomerBasicWizardPage_5);
		
		referencePersonText = new Text(container, SWT.BORDER | SWT.SINGLE);
		referencePersonText.setLayoutData(gd);
		
		setControl(container);
		setPageComplete(false);
	}
	
	private void dialogChanged() {
		if (getName().length() == 0) {
			setDescription(Messages.CustomerBasicWizardPage_6);
			setPageComplete(false);
		} else if (getTaxNumber().length() == 0) {
			setDescription(Messages.CustomerBasicWizardPage_7);
			setPageComplete(false);
		} else {
			setDescription(Messages.CustomerBasicWizardPage_8);
			setPageComplete(true);
		}
	}
	
	public String getName() {
		return nameText.getText().trim();
	}
	
	public String getReferencePerson() {
		return referencePersonText.getText().trim();
	}
	
	public String getTaxNumber() {
		return taxNumberText.getText().trim();
	}
	
	
	public Control getControl() {
		return container;
	}
}
